package cn.lu.joke.util;

import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;

import cn.lu.joke.App;


/**
 * Created by luxianyue on 2018/3/17.
 */

public class HintUtils {
    public static CharSequence getHint(String hint, int size) {
        SpannableString ss = new SpannableString(hint);
        AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size,true);
        ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return ss;
    }

    public static String getColorFontStr(String content, int color) {
        return "<font color='" + color + "'>" + content + "</font>";
    }

    public static Spanned getFormatColorFont(String formatFontStr) {
        return Html.fromHtml(formatFontStr);
    }

    public static Spanned getSpecifyColorFont(String content, int color, int start) {
        return getSpecifyColorFont(content, color, start, content.length());
    }

    public static Spanned getSpecifyColorFont(int stringRes, int color, int start) {
        String content = App.get().getString(stringRes);
        return getSpecifyColorFont(content, color, start, content.length());
    }

    public static Spanned getSpecifyColorFont(int stringRes, int color, int start, int end) {
        return getSpecifyColorFont(App.get().getString(stringRes), color, start, end);
    }

    private static StringBuffer mSb;

    public static Spanned getSpecifyColorFont(String content, int color, int start, int end) {

        if (mSb == null) {
            mSb = new StringBuffer();
        }

        mSb.setLength(0);
        mSb.append(content);
        mSb.replace(start, end, String.format("<font color='"+ color +"'>%s</font>", content.substring(start, end)));
        return Html.fromHtml(mSb.toString());
    }
}
